<?php
/**
 * Created by PhpStorm.
 * User: chy
 * Date: 2017/10/12
 * Time: 下午7:40
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class m_admin_user extends CI_Model
{
    var $ID;
    var $password;

    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    //----------------------------------------------------------------------------------------
    /**
     * load by id
     *
     *
     */
    function load($mID)
    {
        if(!$mID)
        {
            //echo "model 33";
            return array();
        }

        $query = $this->db->get_where('user',array('user_id'=>$mID));

        if($row = $query->row_array())
        {
            return $row;
        }

        return array();
    }


    //--------------------------------------------------------------------------------------------------
    /**
     *登陆后获得操作权限
     *
     *
     */
    function signin()
    {   //echo $this->ID;
//        echo $this->password;
        $sql="select * from admin where admin_name='$this->ID'";
        //$query = $this->db->get_where('user',array('user_id'=>$this->ID,'user_password'=>md5($this->password)));
        //$sql="select * from user where user_id='$this->ID' and user_password='$this->password' and user_status='1'";
        //认证通过
        /*
        if($row = $query->row_array())
        {
            //角色这里的id和manager中的role_id是一个
            $query1 = $this->db->get_where('lib_role',array('id'=>$row['role_id']));
            //将该角色的所有操作放在row1中
            $row1 = $query1->row_array();
            if(!empty($row1))
            {
                $row['action_list'] = $row1['action_list'];
            }
            else
            {
                $row['action_list'] = '';
            }
            return $row;
        }*/
        $query = $this->db->query($sql);
        $temp = $query->result_array();
//        echo $temp[0]['admin_password'];
//        echo $this->password;
        if($this->password==$temp[0]['admin_password']){
             $a=1;
              return $a;
        } else
           return 0;
//        print_r($temp);
        //echo $bac_id;
        //return $temp[0];
    }

    //---------------------------------------------------------------------------------------------
    /**
     *获取用户角色
     *
     *
     */
    function role_user($role_id)
    {
        if(!$role_id)
        {
            return array();
        }

        $query = $this->db->get_where('lib_manager',array('role_id'=>$role_id));

        if($row = $query->row_array())
        {
            return $row;
        }
        return array();
    }


    //--------------------------------
    /**
     * set login time
     *
     */
    function set_login_time($id)
    {
        $datetime = date('Y-m-d H:m:s');
        $this->db->set('lastLoginTime',$datetime);
        $this->db->where('user_id',$id);
        $this->db->update('user');
    }
}
?>